package com.wangsd.web.coupon.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.coupon.entity.BigWheel;
import com.wangsd.web.coupon.entity.BigWheelDetail;
import com.wangsd.web.coupon.entity.Company;
import com.wangsd.web.coupon.service.BigWheelService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-10-22
 */
@Api(value = "大转盘", tags = "大转盘")
@RestController
@RequestMapping("/coupon/bigWheel")
public class BigWheelController extends MyController {
    @Autowired
    BigWheelService bigWheelService;

    @ApiOperation(value = "查看大转盘列表分页", notes = "查看大转盘列表分页", httpMethod = "POST")
    @PostMapping("/selectList/{pageNum}/{pageSize}")
    public Result selectList(@ApiParam(value = "当前页", required = true) @PathVariable Integer pageNum,
                             @ApiParam(value = "每页大小", required = true) @PathVariable Integer pageSize,
                             @RequestBody @ApiParam(name = "bigWheel", value = "传入json格式") BigWheel bigWheel) {
        SysUser userInfo = getUserInfo();
        IPage<BigWheel> bigWheelIPage = bigWheelService.selectPage(userInfo.getCode(), pageNum, pageSize, bigWheel);
        return Result.success(bigWheelIPage);
    }

    @ApiOperation(value = "大转盘修改和保存", notes = "大转盘修改和保存", httpMethod = "POST")
    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@RequestBody BigWheel entity) {
        bigWheelService.addOrUpdate(entity);
        return Result.success();

    }

    @ApiOperation(value = "大转盘删除", notes = "大转盘删除", httpMethod = "GET")
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        bigWheelService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "通过转盘id查询转盘明细", notes = "通过转盘id查询转盘明细", httpMethod = "GET")
    @GetMapping("/selectBigWheelDetailByBigWheelId/{id}")
    public Result selectBigWheelDetailByBigWheelId(@PathVariable Long id) {
        List<BigWheelDetail> bigWheels = bigWheelService.selectBigWheelDetailByBigWheelId(id);
        return Result.success(bigWheels);
    }

    @ApiOperation(value = "商圈转盘上下架操作", notes = "商圈转盘上下架操作", httpMethod = "POST")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody BigWheel bigWheel) {
        bigWheelService.updateStatus(bigWheel);
        return Result.success();
    }
}

